/**
 * Copyright (C) 2010 D. Zoller, M. Richter, M. Blumenstein & W. Biller
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.googlecode.siafu.rest.commands;

import static com.googlecode.siafu.rest.utils.StringUtils.join;

import java.util.LinkedList;
import java.util.List;

import com.googlecode.siafu.rest.model.Agent;
import com.googlecode.siafu.rest.model.Place;
import com.googlecode.siafu.rest.model.Position;

import de.nec.nle.siafu.externalCommand.CommandNames;

/**
 * @author D. Zoller
 * @version $Id: UpdateAgentCommand.java,v 1.6 2010-06-14 08:18:34 nosebrain Exp $
 */
public class UpdateAgentCommand extends UpdateTrackableCommand<Agent> {

	/**
	 * @param trackable the agent to update
	 */
	public UpdateAgentCommand(Agent trackable) {
		super(trackable);
	}
	
	@Override
	protected List<String> getCommands() {
		final List<String> commands = new LinkedList<String>(super.getCommands());
		
		final String agentName = this.trackable.getName();
		
		// auto
		final Boolean auto = this.trackable.isAuto();
		if (auto != null) {
			commands.add(join(CommandNames.AUTO, agentName, auto));
		}
		
		// hide / unhide
		final Boolean visible = this.trackable.isVisible();
		if (visible != null) {
			if (visible) {
				commands.add(join(CommandNames.UNHIDE, agentName));
			} else {
				commands.add(join(CommandNames.HIDE, agentName));
			}
		}
		
		// postition
		final Place destination = this.trackable.getDestination();
		if (destination != null) {
			final Position pos = destination.getPosition();
			if (pos != null) {
				commands.add(join(CommandNames.MOVE, agentName, pos.getLatitude(), pos.getLongitude()));
			}
		}
		
		return commands;
	}
}
